﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using HYFamilyLibDataManager;
using YJKStairs.HYElevator.DataInfo;

namespace YJKStairs.HYElevator.Kit
{
	internal class LoadFamily
	{
		private LoadFamily(ExternalCommandData commandData)
		{
			this.m_Revit = commandData;
			string appRootPath = AssistFunc.GetAppRootPath();
			string versionNumber = this.m_Revit.Application.Application.VersionNumber;
			this.m_strFullPath = appRootPath + "\\FamilyLib\\Family\\";
			this.m_strFullPath += versionNumber;
			this.m_strFullPath += "\\Stairs\\Elevator\\";
		}

		public static LoadFamily GetInstance(ExternalCommandData data)
		{
			LoadFamily.m_Instance = new LoadFamily(data);
			if (!LoadFamily.m_Instance.LoadElavatorFamilys())
			{
				return null;
			}
			return LoadFamily.m_Instance;
		}

		private bool LoadElavatorFamilys()
		{
			try
			{
				this.m_lstFamily = new List<ElementId>();
				Document document = this.m_Revit.Application.ActiveUIDocument.Document;
				IEnumerator<KeyValuePair<FamilyKind, string>> enumerator = KindToFamily.GetInstance().DicFamilyName.GetEnumerator();
				while (enumerator.MoveNext())
				{
					string strFullPath = this.m_strFullPath;
					KeyValuePair<FamilyKind, string> keyValuePair = enumerator.Current;
					string familyFileName = strFullPath + keyValuePair.Value + ".rfa";
					Family family = FamilyUtil.LoadFamily(document, familyFileName);
					this.m_lstFamily.Add(family.Id);
				}
			}
			catch (Exception)
			{
				MessageBox.Show("族文件加载失败!");
				return false;
			}
			return true;
		}

		private ExternalCommandData m_Revit;

		private string m_strFullPath;

		public static LoadFamily m_Instance;

		public List<ElementId> m_lstFamily;
	}
}
